package pl.edu.agh.mguesser.playlist;

import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

/**
 * @author keiran
 */
public class PlaylistImpl implements Playlist {
    
    private int currentIndex = 0;
    private List<Path> songs;

    public PlaylistImpl(List<Path> songs) {
        if(songs == null || songs.isEmpty()) {
            throw new IllegalArgumentException("requires at least one song");
        }
        
        this.songs = songs;
    }
    
    @Override
    public Path getCurrentSong() {
        return songs.get(currentIndex);
    }

    @Override
    public List<Path> getSongs() {
        return Collections.unmodifiableList(songs);
    }

    @Override
    public void randomize() {
        Collections.shuffle(songs);
    }

    @Override
    public void next() {
        if(!hasNext()) {
            throw new IndexOutOfBoundsException();
        }
        
        currentIndex++;
    }

    @Override
    public void previous() {
        if(!hasPrevious()) {
            throw new IndexOutOfBoundsException();
        }
        
        currentIndex--;
    }
    
    @Override
    public boolean hasNext() {
        return currentIndex + 1 < songs.size();
    }
    
    @Override
    public boolean hasPrevious() {
        return currentIndex - 1 >= 0;
    }

    @Override
    public int getSize() {
        return songs.size();
    }
    
    @Override
    public int getCurrentIndex() {
        return currentIndex;
    }
    
}
